import { getuser, clearuser } from '../../utils/storage'
import { request, wxlogin } from '../../utils/https'
import { changepassword } from '../../utils/interfaces'
export default {
  data () {
    return {
      password: '',
      newpassword: ''
    }
  },
  computed: {
    disabled () {
      if (
        this.password === this.newpassword &&
        this.password !== '' &&
        this.newpassword !== ''
      ) {
        return false
      } else {
        return true
      }
    }
  },
  methods: {
    async determine () {
      const {password} = this
      const { ID } = await getuser('user')
      try {
        let code = await wxlogin()
        await request(changepassword, {
          data: {
            ID,
            password,
            code
          }
        })
        await clearuser()
        wx.reLaunch({
          url: '/pages/home/main'
        })
      } catch (err) {
        console.log(err)
        // wx.showModal({
        //   title: "提示",
        //   content: "服务器请求失败，点击确定重新加载",
        //   success: res => {
        //     if (res.confirm) {
        //       this.start();
        //     } else if (res.cancel) {
        //       console.log("用户点击取消");
        //     }
        //   }
        // });
      }
    }
  }
}
